// import { PlatFormServer } from '@/api/PlatFormServer'

function showBigFunc(e) {
  const el = e.srcElement
  const binding = el.showbiginfo
  if (el.errorflag) {
    // console.log('------图片加载出错，不支持点击放大!! -------')
    return
  }
  const imgsrc = (binding.value) ? binding.value : el.src
  zoomDiv = document.createElement('div')
  zoomDiv.addEventListener('click', () => RemoveDiv(null))
  document.addEventListener('keydown', RemoveDiv)
  zoomDiv.innerHTML = `<div style="position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 9999;background: rgba(10, 10, 10, 0.4);display: flex; justify-content: center; align-items: center; cursor: zoom-out;">` +
  `<img style="width: auto;height: auto;max-width: 100%;max-height: 100%;" src="${imgsrc}" /></div>`
  document.body.appendChild(zoomDiv)
}

var zoomDiv = null
function RemoveDiv(e) {
  if (!zoomDiv) return
  if (e && e.keyCode !== 27) return // 键盘点击Esc
  document.removeEventListener('keyup', RemoveDiv)
  document.body.removeChild(zoomDiv)
  zoomDiv = null
  e.stopPropagation()
}

function bind(el, binding) {
  // 添加 点击 事件
  if (el.showbiginfo) {
    el.removeEventListener('click', showBigFunc)
    el.showbiginfo = null
  }
  if (!el.showbiginfo) {
    el.addEventListener('click', showBigFunc)
    el.showbiginfo = binding
  }
}

export default {
  inserted: bind,
  update: bind
}
